package com.leizi.igym.controller.user;

import com.leizi.igym.domain.Region;
import com.leizi.igym.enums.ReturnCodeEnum;
import com.leizi.igym.exception.BusinessException;
import com.leizi.igym.resp.Result;
import com.leizi.igym.service.RegionService;
import com.leizi.igym.utils.ThrowUtils;
import com.leizi.igym.vo.RegionVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @Author: leizi0110
 * @CreateTime: 2024-04-08  09:15
 * @Description:
 */

@RestController("userRegionController")
@RequestMapping("/user/region")
@Tag(name = "用户端-区域相关接口")
@Slf4j
public class RegionController {

    @Resource
    private RegionService regionService;


    @Operation(summary = "用户端：查询所有区域")
    @GetMapping
    public Result<List<RegionVO>> get() {
        return Result.ok(regionService.getAll());
    }

    @Operation(summary = "用户端：根据id查询区域与对应器械")
    @GetMapping("{id}")
    public Result<RegionVO> getWithEquip(@PathVariable("id")Long id) {
        if (Objects.isNull(id) || id <= 0){
            throw new BusinessException(ReturnCodeEnum.PARAMS_ERROR,"区域id有误！");
        }
        RegionVO regionVO = regionService.getByIdWithEquip(id);
        return Result.ok(regionVO);
    }
}
